#include <iostream>

#define IFLINK 0

template <class T>
class Node
{
public:
    T val;
    Node<T>* next = nullptr;

public:
    Node(void) : next(nullptr){}
    Node(T value) : next(nullptr), val(value){}
    ~Node(){}
};

template<class T>
class Stack
{
public:
    Node<T>* top = nullptr;
    int size = 0;

public:
    Stack(void)
    {
        this->top = nullptr;
        this->size = 0;
    }
    ~Stack()
    {
        for(int i=this->size; i>0; i--)
        {
            this->popStack();
        }
    }

    void pushStack(T value)
    {
        Node<T>* newnode = new Node<T>(value);
        newnode->next = top;
        top = newnode;
        this->size++;
    }

    void popStack(void)
    {
        if(this->top == nullptr)
        {
            printf("Stack have no ekement\n");
        }
        Node<T>* temp = this->top;
        this->top = this->top->next;
        delete temp;
        temp = nullptr;
        this->size--;
    }

    void printStack(void)
    {
        if(this->top == nullptr)
        {
            printf("Stack have no ekement\n");
        }

        Node<T>* p = top;
        std::cout << "top ";
        while(p!=nullptr)
        {
            std::cout << p->val << " ";
            p = p->next;
        }
        std::cout << "bottom"<<std::endl;

    }

    int length(void)
    {
        return this->size;
    }



};

template<class T>
class arrayStack
{
public:

    T array[20] = {0};
    int top = 0;
    int size = 0;

public:
    arrayStack() : top(0),size(0){}
    ~arrayStack(){}

    void pushStack(T value)
    {
        if(size>100)
        {
            printf("The stack is full\n");
            return ;
        }
        array[top++] = value;
        this->size++;
    }

    void popStack(void)
    {
        if(top <= 0)
        {
            printf("The stack have no element\n");
            return ;
        }
        array[--top] = 0;
        this->size--;
    }

    void printStack(void)
    {
        if(top <= 0)
        {
            printf("The stack have no element\n");
            return ;
        }
        int temp = top;
        printf("top ");
        while(temp>0)
        {
            printf("%d ", array[--temp]);
        }
        printf("\n");
    }
};




#if IFLINK

int main()
{

    int nums[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int len = sizeof(nums)/sizeof(nums[0]);

    Stack<int>* s = new Stack<int>();

    for(int i=0; i<len; i++)
    {
        s->pushStack(nums[i]);
    }

    s->printStack();

    s->pushStack(100);
    s->printStack();

    s->popStack();
    s->popStack();
    s->popStack();
    s->popStack();
    s->printStack();

    delete s;
    s = nullptr;

    return 0;
}

#else



int main()
{

    int nums[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int len = sizeof(nums)/sizeof(nums[0]);

    arrayStack<int>* s = new arrayStack<int>();

    for(int i=0; i<len; i++)
    {
        s->pushStack(nums[i]);
    }

    s->printStack();

    s->pushStack(100);
    s->printStack();

    s->popStack();
    s->popStack();
    s->popStack();
    s->popStack();
    s->printStack();

    delete s;
    s = nullptr;

    return 0;
}



#endif